package org.ch02.hw.demo05;

import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Scanner;

/**
 * @author ZJL
 * @date 2025-03-17
 */
public class MainTest01 {
    public static void main(String[] args) throws Exception {
        //        五、使用反射机制来实现用户输入一个年份，判断是闰年还是平年
//                Scanner sc = new Scanner(System.in) ;
//                sc.nextInt() ;

        System.out.println("输入一个年份，判断是闰年还是平年");
        Class<Scanner> clazz = Scanner.class;
        Constructor<Scanner> constructor = clazz.getConstructor(InputStream.class);
        Scanner scanner = constructor.newInstance(System.in);
        Method nextInt = clazz.getMethod("nextInt");
        int n = (int) nextInt.invoke(scanner);
        if ((n % 400 == 0) || (n % 4 == 0 && n % 100 != 0)) {
            System.out.println(n+"年是闰年");
        } else {
            System.out.println(n+"年是平年");
        }
    }
}
